<?php

use common\helpers\Html;
use common\enums\ConfigTypeEnum ;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\CommonSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '配置管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="config-dao-index">


    <p>

        <?= Html::create(['ajax-edit'], '配置', [
            'data-toggle' => 'modal',
            'data-target' => '#ajaxModal',
            'class' => 'btn btn-success',
        ]); ?>

    </p>


    <div class="active tab-pane">
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            //重新定义分页样式
            'tableOptions' => ['class' => 'table table-hover'],
            'columns' => [
                [
                    'class' => 'yii\grid\SerialColumn',
                ],
                'title',
                'name',
                [
                    'attribute' => 'sort',
                    'value' => function ($model) {
                        return Html::sort($model->sort);
                    },
                    'filter' => false,
                    'format' => 'raw',
                    'headerOptions' => ['class' => 'col-md-1'],
                ],
                [
                    'label' => '类别',
                    'attribute' => 'cate.title',
                    'filter' => Html::activeDropDownList($searchModel, 'cate_id', $cateDropDownList, [
                            'prompt' => '全部',
                            'class' => 'form-control'
                        ]
                    ),
                ],
                [
                    'label' => '属性',
                    'attribute' => 'type',
                    'value' => function ($model, $key, $index, $column) {
                        return ConfigTypeEnum::getValue($model->type);
                    },
                    'filter' => Html::activeDropDownList($searchModel, 'type',
                        ConfigTypeEnum::getMap(), [
                            'prompt' => '全部',
                            'class' => 'form-control'
                        ]
                    ),
                    'headerOptions' => ['class' => 'col-md-1'],
                ],
                [
                    'header' => "操作",
                    'class' => 'yii\grid\ActionColumn',
                    'template' => '{edit} {status} {destroy}',
                    'buttons' => [
                        'edit' => function ($url, $model, $key) {
                            return Html::edit(['ajax-edit', 'id' => $model->id], '编辑', [
                                'data-toggle' => 'modal',
                                'data-target' => '#ajaxModal',
                            ]);
                        },
                        'status' => function ($url, $model, $key) {
                            return Html::status($model->status);
                        },
                        'destroy' => function ($url, $model, $key) {
                            return Html::delete(['delete', 'id' => $model->id]);
                        },
                    ],
                ],
            ],
        ]); ?>
    </div>


</div>
